package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbVmTypeMapper;
import com.heima.pojo.TbVmType;
import com.heima.pojo.vo.PageResponse;
import com.heima.service.ITbVmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 售货机类型表 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-10
 */
@Service
public class TbVmTypeServiceImpl extends ServiceImpl<TbVmTypeMapper, TbVmType> implements ITbVmTypeService {

    @Autowired
    TbVmTypeMapper vmTypeMapper;
    /**
     * 设备搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public PageResponse<TbVmType> getByPage(Integer pageIndex, Integer pageSize, String name) {
        Page<TbVmType> page = new Page<>(pageIndex, pageSize);

        Page<TbVmType> vmTypePage = vmTypeMapper.getByPage(page, name);
        PageResponse<TbVmType> pageResponse = new PageResponse<>();
        pageResponse.setPageIndex(vmTypePage.getCurrent());
        pageResponse.setPageSize(vmTypePage.getSize());
        pageResponse.setTotalPage(vmTypePage.getPages());
        pageResponse.setTotalCount(vmTypePage.getTotal());
        pageResponse.setCurrentPageRecords(List.copyOf(vmTypePage.getRecords()));
        return pageResponse;
    }
}
